package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.Path;
import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {

    @Autowired
    private MovementManager movementManager;

    // 发布动态  Content-Type	multipart/form-data
    @PostMapping("/movements")
    public ResponseEntity saveMovement(Movement movement, MultipartFile[] imageContent) throws IOException {
        // 调用manager
        return movementManager.saveMovement(movement, imageContent);
    }

    // 查询个人动态
    @GetMapping("/movements/all")
    public ResponseEntity findMyMovementByPage(
            Long userId,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return movementManager.findMyMovementByPage(userId, pageNum, pageSize);
    }

    // 查询好友动态
    @GetMapping("/movements")
    public ResponseEntity findFriendMovementByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return movementManager.findFriendMovementByPage(pageNum, pageSize);
    }

    // 查询推荐动态
    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovementByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return movementManager.findRecommendMovementByPage(pageNum, pageSize);
    }

    // 点赞
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity movementLike(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementLike(publishId);
    }

    // 取消点赞
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity movementDislike(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementDislike(publishId);
    }

    // 喜欢
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity movementLove(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementLove(publishId);
    }

    // 取消喜欢
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity movementUnlove(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementUnlove(publishId);
    }

    // 单条动态查询
    @GetMapping("/movements/{publishId}")
    public ResponseEntity findMovementDetail(@PathVariable String publishId) {
        // 调用manager
        return movementManager.findMovementDetail(publishId);
    }

    // 评论列表
    @GetMapping("/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(value = "movementId") String publishId,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return movementManager.findCommentVoByPage(publishId, pageNum, pageSize);
    }

    // 发表评论
    @PostMapping("/comments")
    public ResponseEntity movementComment(@RequestBody Map<String,String> param){
        // 1.接收参数
        String publishId = param.get("movementId");
        String content = param.get("comment");
        // 2.调用mananger
        return movementManager.movementComment(publishId,content);
    }

    // 评论点赞
    @GetMapping("/comments/{movementCommentLike}/like")
    public ResponseEntity movementCommentLike( @PathVariable String movementCommentLike   ){
        // 调用manager
        return movementManager.movementCommentLike(movementCommentLike);

    }

    // 评论点赞-取消
    @GetMapping("/comments/{movementCommentDislike}/dislike")
    public ResponseEntity movementCommentDislike( @PathVariable String movementCommentDislike  ){
        // 调用manager
        return movementManager.movementCommentDislike(movementCommentDislike);

    }
}
